package com.snail.snailvr.network;




import com.android.volley.ParseError;
import com.android.volley.Response;
import com.android.volley.ServerError;
import com.android.volley.VolleyError;
import com.snail.snailvr.VRApp;


/**
 * 网络请求辅助类
 * <p/>
 * Created by xixh on 2015/6/17.
 */
public class RequestHelper {
    /**
     * 新建网络Get请求
     *
     * @param url         请求地址
     * @param tag         Tag，用于取消请求
     * @param clazz       响应数据结构类
     * @param iFSResp     回调
     * @param <T>         响应数据结构类
     * @param shouldCache 是否保存缓存
     * @param extendJson  Json解析方式
     */
    public static <T> void newGetRequest(int method,String url, String tag, final Class<T> clazz, final IFSResponse<T> iFSResp
            , boolean shouldCache, boolean extendJson,boolean isHomeJson) {
        FSRequest request = new FSRequest(method, url, tag, clazz, new Response.Listener<T>() {

            @Override
            public void onResponse(T response) {
                iFSResp.onSuccess(response);

            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                if (error instanceof ServerError ||
                        error instanceof ParseError)
                    iFSResp.onServerError();
                else
                    iFSResp.onNetWorkError();
            }
        }, extendJson,isHomeJson);

        request.setShouldCache(shouldCache);
        VRApp.getRequestQueue().add(request);
    }

}

